Update Event with Progress
Description
The update_event_with_progress
function sends a PUT request to update an event with additional progress information. It updates the status, result, and includes the progress percentage for the event, along with other event details like process ID, tags, and attempt number. The function returns a WebServiceResult
object that contains the response code, response string, and parsed JSON data if available.
Function Signature:
def update_event_with_progress(ws_config: WebServiceConfig, event_id: int, event_status: int, result: str, process_id: int, tag_string: str ='', tag_number: int = 0, percent_complete: float = 0, attempt_number: int = 1) -> WebServiceResult:
Parameters
- ws_config (WebServiceConfig): Configuration for the web service connection.
- event_id (int): The ID of the event to update.
- event_status (int): The new status of the event.
- result (str): The result of the event (e.g., success or failure).
- process_id (int): The process ID associated with the event.
- tag_string (str, optional): Optional string tag to associate with the event (default is an empty string).
- tag_number (int, optional): Optional numeric tag to associate with the event (default is 0).
- percent_complete (float, optional): The percentage of completion for the event (default is 0).
- attempt_number (int, optional): The attempt number for the event (default is 1).
Returns
- WebServiceResult: A result object containing:
http_response_code
: The response code from the web service.http_response_string
: The response string from the web service.json_data
: The parsed JSON response from the web service, orNone
if there was an error.code
: A status code (0 for success, -1 for failure).description
: A description of any error that occurred.
Example Usage
ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
event_id = 123
event_status = 1
result = "In Progress"
process_id = 456
tag_string = "TestTag"
tag_number = 5
percent_complete = 50.0
attempt_number = 2
result = update_event_with_progress(ws_config, event_id, event_status, result, process_id, tag_string, tag_number, percent_complete, attempt_number)
print(result.http_response_code)
print(result.json_data)
Behavior
- The function sends a PUT request to update the event with the provided details.
- The request payload includes information such as event status, result, process ID, tags, percent complete, and attempt number.
- The response is parsed into a
WebServiceResult
object, which contains the response code, response string, and parsed JSON data. - If the response string is not empty, it attempts to parse the JSON response and include it in the result.
- Any errors during the request or JSON processing are caught, and an exception description is added to the result.
Error Handling
- General Exception: Any errors during the request or JSON processing will be caught, and the error description will be included in the result.
- Exception Information: The function prints the filename and line number for easier debugging when an exception is encountered.